//
//  DoctorApplyController.m
//  QuickCure1
//
//  Created by maoge on 16/10/30.
//  Copyright © 2016年 maoge. All rights reserved.
//

#import "DoctorApplyController.h"
#import "DoctoryApplyCell.h"
#import "DoctorApplyDetailVc.h"
#import "DoctorApplyModel.h"


@interface DoctorApplyController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UILabel *lb_nothing;

@end

@implementation DoctorApplyController

//#pragma mark - 重写init接口
//- (instancetype)initWithUrl:(NSArray *)modelList {
//    
//    if (self = [super init]) {
//        
//        //获取网络数据
//        [DoctorApplyModel getModelListWithURL:urlString Complete:^(NSArray<DoctorApplyModel *> *modelList, NSError *error) {
//            
//            _modelList = modelList;
//        }];
//    }
//    
//    return self;
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
    
    _modelList = [UserManager sharedManager].famousDoctorModelList;
    
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    if (_modelList.count == 0) {
        
        _lb_nothing = [[UILabel alloc] initWithFrame:CGRectZero];
        
        [self.view addSubview:_lb_nothing];
        
        _lb_nothing.text = @"还没有任何申请~😯";
        _lb_nothing.font = MYROUNDFONT(17);
        
        [_lb_nothing mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.view);
            make.top.equalTo(self.view).offset(200);
        }];
    }
}


#pragma mark - 搭建UI
- (void)setupUI {
    
    ///替换系统返回箭头
    UIImage *image = [[UIImage imageNamed:@"jiantou"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithImage:image style:UIBarButtonItemStyleDone target:nil action:nil];
    
    self.navigationItem.backBarButtonItem = backItem;
    
    [self.navigationController.navigationBar setBackIndicatorImage:[UIImage new]];
    [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage new]];
    
    
    ///-----------------------------------------------------------------------------tableview
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    [self.view addSubview:tableView];
    
    [tableView registerNib:[UINib nibWithNibName:@"DoctoryApplyCell" bundle:nil] forCellReuseIdentifier:@"applyCell"];
    
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.view);
    }];
    
    tableView.dataSource = self;
    tableView.delegate = self;
    
    tableView.estimatedRowHeight = UITableViewAutomaticDimension;
    tableView.estimatedRowHeight = 100;
    
    //去掉多余的线
    tableView.tableFooterView = [[UIView alloc]init];
}

#pragma mark - tableView dataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return self.modelList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    DoctoryApplyCell *cell = [tableView dequeueReusableCellWithIdentifier:@"applyCell" forIndexPath:indexPath];
    
    DoctorApplyModel *model = _modelList[indexPath.row];
    
    cell.model = model;
    
    
    return cell;
}

#pragma mark - 点击某行跳转
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //获取病人详情vc
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"DoctorApplyDetailVc" bundle:[NSBundle mainBundle]];
    DoctorApplyDetailVc *detailVc = [sb instantiateInitialViewController];
    
    //给下一个vc传值
    detailVc.modelList = _modelList;
    detailVc.indexPath = indexPath;
    
    //跳转
    [self.navigationController pushViewController:detailVc animated:YES];

}


- (void)dealloc {
    
    NSLog(@"名医通申请释放");
}



@end



































